package chixing.day11.work.w10;
// 买一赠一策略
public class BuyOneGetOneStrategy implements PricingStrategy {
    @Override
    public double calculate(Product product) {
        int quantity = product.getQuantity();
        double price = product.getPrice();

        // 偶数件：一半数量 × 单价；奇数件：(数量+1)/2 × 单价
        int effectiveQuantity = (quantity + 1) / 2;
        return effectiveQuantity * price;
    }

    @Override
    public String toString() {
        return "买一赠一";
    }
}

